package io.mybatis.example.springboot.controller;

import io.mybatis.common.core.DataResponse;
import io.mybatis.common.core.RowsResponse;

import io.mybatis.example.springboot.model.QrtzCalendars;
import io.mybatis.example.springboot.service.QrtzCalendarsService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * QRTZ_CALENDARS - 日历信息表
 *
 * @author mkj
 */
@RestController
@RequestMapping("qrtzCalendarses")
public class QrtzCalendarsController {

  @Autowired
  private QrtzCalendarsService qrtzCalendarsService;

  @PostMapping
  public DataResponse<QrtzCalendarsDO> save(@RequestBody QrtzCalendarsDO qrtzCalendars) {
    return DataResponse.ok(qrtzCalendarsService.save( qrtzCalendars));
  }

  @GetMapping
  public RowsResponse<QrtzCalendarsDO> findList(@RequestBody QrtzCalendarsDO qrtzCalendars) {
    return RowsResponse.ok(qrtzCalendarsService.findList( qrtzCalendars));
  }

  @GetMapping(value = "/{id}")
  public DataResponse<QrtzCalendarsDO> findById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzCalendarsService.findById(id));
  }

  @PutMapping(value = "/{id}")
  public DataResponse<QrtzCalendarsDO> update(@PathVariable("id") Long id, @RequestBody QrtzCalendarsDO qrtzCalendars) {
    qrtzCalendars.setId(id);
    return DataResponse.ok(qrtzCalendarsService.update( qrtzCalendars));
  }

  @DeleteMapping(value = "/{id}")
  public DataResponse<Boolean> deleteById(@PathVariable("id") Long id) {
    return DataResponse.ok(qrtzCalendarsService.deleteById(id) == 1);
  }

}
